package com.bluegalaxy.nhb.snapi.controller.api.ck;

import com.alibaba.fastjson.JSONObject;
import com.bluegalaxy.nhb.snservice.domain.constant.AppConstant;
import com.bluegalaxy.nhb.snservice.domain.vo.api.R;
import com.bluegalaxy.nhb.snservice.domain.vo.api.ck.FunnelParamVO;
import com.bluegalaxy.nhb.snservice.domain.vo.api.ck.KeepParamVO;
import com.bluegalaxy.nhb.snservice.service.ck.UserGroupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户分群
 */
@RestController
@RequestMapping(AppConstant.APPLICATION_NAME+"/user/group")
@Api(value = "用户分群", tags = "用户分群API")
public class UserGroupController {
    private static Log log = LogFactory.getLog(UserGroupController.class);

    @Autowired
    private UserGroupService userGroupService;


    @ResponseBody
    @PostMapping("/findCount")
    @ApiOperation(value = "根据条件查询人数", notes = "根据条件查询人数")
    public R findCount(@RequestBody JSONObject  paramVO) {
        log.info("user/group findCount:"+JSONObject.toJSONString(paramVO));
        return userGroupService.countUsers(paramVO);
    }

    @ResponseBody
    @PostMapping("/findUsers")
    @ApiOperation(value = "根据条件查询userList", notes = "根据条件查询userList")
    public R findUsers(@RequestBody JSONObject  paramVO) {
        log.info("user/group findUsers:"+JSONObject.toJSONString(paramVO));
        return userGroupService.findUsersById(paramVO);
    }

    @ResponseBody
    @GetMapping("/find/{tableId}")
    @ApiOperation(value = "根据tableId查询userList", notes = "根据tableId查询userList")
    public R findUsersById(@PathVariable("tableId") String tableId) {
        List<String> users = new ArrayList<>();

        return R.data(users);
    }

    @ResponseBody
    @PostMapping("/createUsers")
    @ApiOperation(value = "根据条件创建用户分群", notes = "根据条件创建用户分群")
    public R createUsers(@RequestBody JSONObject  paramVO) {
        log.info("user/group createUsers:"+JSONObject.toJSONString(paramVO));
        return userGroupService.createUsers(paramVO);
    }

    @ResponseBody
    @PostMapping("/createUsersByKeep")
    @ApiOperation(value = "留存分析-创建用户分群", notes = "根据条件创建用户分群")
    public R createUsersByKeep(@RequestBody KeepParamVO paramVO) {
        List<String> users = new ArrayList<>();
        log.info("user/group createUsersByKeep:"+JSONObject.toJSONString(paramVO));
        return userGroupService.createUsersByKeep(paramVO);
    }

    @ResponseBody
    @PostMapping("/createUsersByFunnel")
    @ApiOperation(value = "漏斗分析-创建用户分群", notes = "根据条件创建用户分群")
    public R createUsersByFunnel(@RequestBody FunnelParamVO paramVO) {
        List<String> users = new ArrayList<>();
        log.info("user/group createUsersByFunnel:"+JSONObject.toJSONString(paramVO));
        return userGroupService.createUsersByFunnel(paramVO);
    }


}
